//
//  CourierListViewController.m
//  LuxuryGoods
//
//  Created by DCQ on 2018/8/5.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "CourierListViewController.h"
#import "CourierListCell.h"

NSString * const CourierListCellIdentifier = @"CourierListCellIdentifier";
@interface CourierListViewController ()
@property (nonatomic, strong) NSArray * listData;
@end

@implementation CourierListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self requestCourierList];
}

- (void)requestCourierList{
    WEAKSELF
    [[MainApi sharedInstance] postPath:@"Index/getExpressList" params:nil resultBlock:^(NSDictionary *responseObject, NSError *error) {
        STRONGSELF
        NSLog(@"%@===",responseObject);
        if (responseObject && !error) {
           
            self.listData = responseObject[@"data"];
        }
        [strongSelf.tableView reloadData];
    }];
    
}

- (void)registerCell{
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([CourierListCell class]) bundle:nil] forCellReuseIdentifier:CourierListCellIdentifier];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    NSInteger section =   0;
    if (self.listData) {
        section =  1;
    }
    return section;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger row = [self.listData count];
   
    return row;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = nil;
    CourierListCell * tempCell = [tableView dequeueReusableCellWithIdentifier:CourierListCellIdentifier];
    [tempCell setupNameLabel:self.listData[indexPath.row][@"express_name"]];
    cell = tempCell;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat height = 44;
    return height;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.chooseCourierBlock) {
        self.chooseCourierBlock(self.listData[indexPath.row]);
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
